﻿package
{
	import org.flixel.*;
	//import org.flixel.plugin.photonstorm.FlxCollision;
	//import org.flixel.plugin.photonstorm.FlxBar;
	//import org.flixel.plugin.photonstorm.FlxWeapon;
	//import org.flixel.plugin.photonstorm.FlxButtonPlus;
	
	public class Level1 extends FlxState
	{	
		[Embed(source="data/tiles1.png")] private var ImgTiles:Class;
		[Embed(source ="data/map1.csv", mimeType = "application/octet-stream")] private var MapData:Class;

			var _level:FlxTilemapExt;
			var masa1:masa;
			var masa2:masa;
			var masa3:masa;
			var player:Player;
			var allCharges:FlxGroup;	

	
		override public function create():void
		{			
			super.create()
		
			_level = new FlxTilemapExt();
			_level.loadMap(new MapData,ImgTiles);
			add(_level);
			FlxG.camera.setBounds(0, 0, _level.width, _level.height, true);
			allCharges = new FlxGroup();
			
			masa1 = new masa(255,60,10,allCharges);
			masa2 = new masa(120,45,-10,allCharges);
			masa3 = new masa(45,180,10,allCharges);
			
			player = new Player(165,120,allCharges);
			//add(player);
			
			allCharges.add(masa1);
			allCharges.add(masa2);
			allCharges.add(masa3);
			allCharges.add(player);
			
			
									
			FlxG.camera.follow(player, FlxCamera.STYLE_LOCKON);
			
		}


		
		override public function destroy():void
		{
			super.destroy();
			player = null;
		}
		
		
		override public function update():void
		{
			super.update();
			FlxG.collide();
			
			if(FlxG.keys.R)
				FlxG.resetState();
			if(FlxG.keys.T) trace(player.x,player.y);	
			if(FlxG.keys.Y) trace(_level.width,_level.height);
			
			if(player.x > _level.width) player.x = 0;
			if(player.y > _level.height) player.y = 0;
			if(player.x < 0) player.x = _level.width;
			if(player.y < 0) player.y = _level.height;
			//player.velocity.x
			//_level.getBounds
			//_level.scrollFactor

		}
	}
}
